<?php namespace Admin\Controller;
//类型属性控制器
class TypeAttrController extends CommonController{
	private $model;
	public function __auto(){
		$this->model=new \Common\Model\TypeAttr;
	}
	
	//类型属性模板
	public function index(){
		$tid=Q('get.tid',0,'intval');
		$data=$this->model
			 ->where("type_tid={$tid}")
			 ->get();
		View::with('data',$data);
//		p($data);
		View::make();
	}
	//添加属性
	public function add(){
		$type_tid=Q('get.type_tid',0,'intval');
		if(IS_POST){
//			p(Q('post.'));die;
			if($this->model->store()){
				View::success('添加成功',U('index',array("tid"=>$type_tid)));
			}
		View::error($this->model->getError());
			
		}
		View::make();
	}
	//修改
	public function edit(){
		$taid=Q('get.taid',0,'intval');
		$data=$this->model
				->where("taid={$taid}")
				->find();
		$type_tid=$data['type_tid'];
		if(IS_POST){
			if($this->model->edit()){
			View::success("数据修改成功",U('index',array("tid"=>$type_tid)));
			}
		View::error($this->model->getError());
		}
		//显示据数据
		$taid=Q('get.taid',0,'intval');
		$oldData=$this->model
				->where("taid={$taid}")
				->find();
		View::with('oldData',$oldData);
		View::make();
	}
	//删除
	public function del(){
		$taid=Q('get.taid',0,'intval');
		$this->model->where("taid={$taid}")->delete();
		View::success("删除成功");
		
	}
	
	
}